<template>
  <div class="technical_notices">
    <!--附件详情-->
    <annex-detail ref="AnnexDetail"></annex-detail>
    <one-title title="技术通知单" @refreshData="refresh">
      <div class="mes_btn">
        <el-button
          v-btn-permission="'getAnnex'"
          size="small" @click="getAnnex">
          <i class="iconfont icon-tongbu"></i>
          获取附件
        </el-button>
      </div>
    </one-title>
    <div class="fixed_top_56">
      <mes-search-comp
        :searchList="searchList"
        ref="mesSearch"
        :searchResult="searchCount"
        @searchInfo="_info">
      </mes-search-comp>
      <div class="table_container">
        <el-table
          ref="tableNode"
          v-loading="isLoading"
          border
          stripe
          :data="listData.list"
          :max-height="tableMaxHeight"
          @sort-change="_sort"
          tooltip-effect="dark">
          <mes-col-comp
            :key="index"
            v-for="(column,index) in columnList"
            :column="column">
          </mes-col-comp>
          <el-table-column
            prop=""
            label="操作"
            show-overflow-tooltip
            align="center"
            fixed="right"
            :resizable="false"
            min-width="90">
            <template slot-scope="scope">
              <span class="jump_item is_disabled" v-if="isClass(scope.row.statusValue)">附件详情</span>
              <span class="jump_item" v-else @click="annexDetail(scope.row)">附件详情</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <mes-pagination
        @updateData="init"
        :currentPage="listData.pageNo"
        :total="listData.count || 0"
        :pageSize="listData.pageSize">
      </mes-pagination>
    </div>
  </div>
</template>

<script>
import tableColumns from './tableColumns'
import AnnexDetail from './AnnexDetail'

let Uploaded = 'Uploaded'
export default {
  name: 'TechnicalNotices',
  components: {
    AnnexDetail
  },
  data() {
    return {
      tableColConfig: tableColumns, // 列配置
      isLoading: false, // 是否加载
      searchCount: NaN, // 搜索结果数
      searchData: [], // 搜索的数据
      sortData: [], // 排序
    }
  },
  computed: {
    // 列表查询
    listData() {
      // return this.$store.state.technicalNotices.listData
      return this.$store.state.deviceDataUpload.listData
    },
    // 搜索项
    searchList() {
      let searchList = this.tableColConfig || []
      return searchList
    },
    // 列循环
    columnList() {
      this.$nextTick(() => {
        this.$refs.tableNode.doLayout()
      })
      return this.tableColConfig.filter(item => item.noForCol !== true && item.isShow !== false)
    },
  },
  mounted() {
    this.init()
  },
  methods: {
    // 刷新
    refresh() {
      this.searchData = {} // 查询参数
      this.sortData = {} // 排序对象
      this.$refs.mesSearch.clean()
      this.$refs.tableNode.clearSort()
      this.init()
    },
    init(page) {
      this.isLoading = true
      let postData = {
        method: 'post',
        url: 'a/deviceuploaddata/deviceUploadData/list',
        data: {
          pageNo: page ? page.pageNo : 1,
          pageSize: page ? page.pageSize : this.listData.pageSize || 15
        },
        module: 'deviceDataUpload',
        state: 'listData'
      }
      if (Object.keys(this.searchData).length > 0) {
        postData.data.query = this.searchData
      }
      if (Object.keys(this.sortData).length > 0) {
        postData.data.sort = this.sortData
      }
      this.$store.dispatch('saveData', postData).then((res) => {
        if (Object.keys(this.searchData).length > 0) {
          this.searchCount = res.count
        } else {
          this.searchCount = NaN
        }
      }).finally(() => {
        this.isLoading = false
      })
    },
    // 获取附件
    getAnnex() {

    },
    // 附件详情
    annexDetail(row) {
      console.log(row)
      this.$refs.AnnexDetail.openDialog(row)
    },
    // 搜索
    _info(data) {
      this.searchData = data
      this.init()
    },
    // 排序
    _sort(obj) {
      this.sortData = this.$getSortOrder(obj)
      this.init()
    },
    // 判断附件详情是否禁用
    isClass(type) {
      switch (type) {
        case Uploaded:
          return false
        default:
          return true
      }
    },
  }
}
</script>

<style scoped>

</style>
